package com.trkj.vo;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import org.springframework.context.ApplicationContext;
import org.springframework.web.servlet.support.RequestContextUtils;

import com.trkj.pojos.Tbpower;
import com.trkj.service.HwcPowerService;
/**
 * 对权限进行判定
 * @author lenovo
 *
 */
public class PowerTag extends SimpleTagSupport {
	
	private long pid;

	public long getPid() {
		return pid;
	}

	public void setPid(long pid) {
		this.pid = pid;
	}
	
	@Override
	public void doTag() throws JspException, IOException {
		// TODO Auto-generated method stub
		super.doTag();
		PageContext pageContext = (PageContext) getJspContext();
		//获取Spring容器
		ApplicationContext ac = RequestContextUtils.findWebApplicationContext((HttpServletRequest) pageContext.getRequest());
		//从Session中获取用户ID
		HwcPowerService powerService = ac.getBean(HwcPowerService.class);
		
		//从session中获取用户账号
		String account = (String) pageContext.getSession().getAttribute("account"); 
		//System.out.println("从session中获取的用户账号"+account);
		//获取用户所有的权限
		List<Tbpower> list  = powerService.findStaffNOBypowersNo(account);
		/*for(Tbpower t:list){
			//输出看看list
			//System.out.println("用户获取的权限"+t.getPowerNo()+"名称"+t.getPowerGrade());
		}*/
		//判断是否在list集合中
		boolean flag = false;
		if(list != null){
			for(Tbpower power:list){
				//System.out.println("判断是否在集合中"+power.getPowerNo());
				if(power.getPowerNo() == pid){
					
					flag = true;
					break;
				}
			}
		}
		if(flag){
			//输出标签内容
			getJspBody().invoke(null);
		}
	
	}
	
}
